import logging

log = logging.getLogger(__name__)

formatter = logging.basicConfig(
    level=logging.DEBUG,
    format=
    '%(asctime)s %(filename)s[line:%(lineno)d] %(levelname)s %(message)s',
    datefmt='%a, %d %b %Y %H:%M:%S')

try:
    from info_config import get_backup_info_url

except ImportError as e:
    from info_config import get_backup_info_url

try:
    from urllib.parse import urlencode
    from urllib.request import Request, urlopen
    import json

except ImportError as e:
    from urllib.parse import urlencode
    from urllib.request import Request, urlopen
    import json


def get_file_backup_info(mysql_host, mysql_port):
    mysql_instance = {"mysql_host": mysql_host, "mysql_port": mysql_port}
    mysql_instance = json.dumps(mysql_instance)
    req = Request(url=get_backup_info_url,
                  data=bytes(mysql_instance.encode("utf-8")),
                  method="GET")
    req.add_header("Content-type", "application/json; charset=UTF-8")

    with urlopen(req) as resp:
        response_data = json.loads(resp.read().decode("utf-8"))
        print(response_data)
        return response_data
